package org.ucas.faker.web.fetcher.meta;

import java.io.Serializable;

public class FetchField implements Serializable {

  public String name;

  public Class javaType;

  public ColumnField column;

  public FetchField(ColumnField column) {
    this(column,null);
  }

  public FetchField(ColumnField f, String name) {
   this.column = f;
   if(name != null) this.name = name;
   else if(f.alias != null) {
     this.name = f.alias.equals(f.column)? null : f.alias;
   }
  }

  public String sql() {
    if(name != null) return column.sql() + " AS " + name;
    return column.alias == null || column.alias.equals(column.column)? column.sql() : column.sql() + " AS " + column.alias;
  }
}
